<?php

class TestimonyController extends AdminController {

    public function filters() {
        return array(
            'accessControl', // perform access control for CRUD operations
        );
    }

    public function actionList() {
        $model = new sys_member_testimony('search');
        $model->unsetAttributes();  // clear any default values
        if (isset($_GET['sys_member_testimony']))
            $model->attributes = $_GET['sys_member_testimony'];
        
        $this->render('list', array(
            'model' => $model,
        ));
    }
    
    public function actionPublish() {
        if (isset($_POST['publish'])) {
            if (is_array($_POST['item'])) {
                foreach ($_POST['item'] as $id => $value) {
                    //update datanya
                    Yii::app()->db->createCommand()->update('sys_member_testimony', array('member_testimony_is_approve' => '1'),
                                                            'member_testimony_id=:id',array(':id' => $value));
                }
                Yii::app()->user->setFlash('success', 'Testimony has been published.');
            } else {
                Yii::app()->user->setFlash('error', 'Publish Testimony failed.');
            }
        } elseif(isset($_POST['unpublish'])) {
            if (is_array($_POST['item'])) {
                foreach ($_POST['item'] as $id => $value) {
                    //update datanya
                    Yii::app()->db->createCommand()->update('sys_member_testimony', array('member_testimony_is_approve' => '0'),
                                                            'member_testimony_id=:id',array(':id' => $value));
                }
                Yii::app()->user->setFlash('success', 'Testimony has been unpublished.');
            } else {
                Yii::app()->user->setFlash('error', 'Unpublish Testimony failed.');
            }
        } else {
            Yii::app()->user->setFlash('error', 'Publish / Unpublish Testimony failed.');
        }
        
        $this->redirect(array('list'));
    }
    
    public function actionView($id) {
        $this->render('view', array(
            'model' => $this->loadModel($id),
        ));
    }
    
    public function loadModel($id) {
        $model = sys_member_testimony::model()->findByPk($id);
        if ($model === null)
            throw new CHttpException(404, 'The requested page does not exist.');
        return $model;
    }

}